import MobileDetect from 'mobile-detect'
import mobile from '@/utils/mobile.js'
const judgeBrand = mobile.judgeBrand

export const detectMobile = () => {
	const userAgent = window.navigator.userAgent
	const md = new MobileDetect(userAgent)
	const os = md.os() //获取系统
	let HMS = ''
	// 获取华为
	if (userAgent.split(')')[0].includes('HMSCore')) {
		HMS = userAgent.split(')')[0].split('HMSCore')[0].split(';')
	}
	let model = HMS[HMS.length - 2]
	let val
	if (os == 'iOS') {
		val = 'apple'
	} else if (os == 'AndroidOS') {
		//Android系统的处理
		let j
		const sss = userAgent.split(';')
		for (let i = 0; i < sss.length; i++) {
			if (sss[i].indexOf('Build/') > 0) {
				j = i
				break
			}
		}
		// @ts-ignore
		if (j > -1) {
			// @ts-ignore
			model = sss[j].substring(0, sss[j].indexOf('Build/'))
		}

		console.log('model__', model)
		
		
		console.log('judgeBrand', userAgent)

		val = judgeBrand(userAgent.toLowerCase())
	}
	val = val ? val : '其他型号手机'
	console.log('手机型号为：', val)
	return val.toLowerCase()
}